package cn.tangsihai.hrm;

import cn.tangsihai.hrm.doc.CourseESDoc;
import cn.tangsihai.hrm.repository.CourseElasticsearchRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.test.context.junit4.SpringRunner;

// 使用测试生成索引库
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SearchApplication.class)
public class Creat {
    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;
    @Autowired
    private CourseElasticsearchRepository repository;
    @Test
    public void testName (){
        // 创建索引
        elasticsearchTemplate.createIndex(CourseESDoc.class);
        // 建立映射
        elasticsearchTemplate.putMapping(CourseESDoc.class);
    }

    @Test
    public void add (){
        CourseESDoc esDoc = new CourseESDoc();
        esDoc.setId(1L);
        esDoc.setChargeName("sdfhjsdhfj");
        repository.save(esDoc);
    }
}
